package com.novak.rss.reader;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class FeedsListAdapter extends BaseAdapter
{
  private LayoutInflater inflater;
  private List<Feed> feeds;

  public FeedsListAdapter(Context context, List<Feed> feeds)
  {
    this.inflater = LayoutInflater.from(context);
    this.feeds = feeds;
  }

  @Override
  public int getCount()
  {
    return feeds.size();
  }

  @Override
  public Object getItem(int position)
  {
    return feeds.get(position);
  }

  @Override
  public long getItemId(int position)
  {
    return position;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup par)
  {
    ViewHolder holder;

    if (convertView == null)
    {
      convertView = inflater.inflate(R.layout.feed_list_row, null);
      holder = new ViewHolder();
      holder.text = (TextView) convertView.findViewById(R.id.text);
      convertView.setTag(holder);
    } else
    {
      holder = (ViewHolder) convertView.getTag();
    }
    Feed tmpN = (Feed) feeds.get(position);
    holder.text.setText(tmpN.getName());

    return convertView;
  }

  private class ViewHolder
  {
    TextView text;
  }
}
